// 获取当前用户状态
const {
    Mysql,
    encrypt
} = require('../tools/utils');
module.exports = async (ctx) => {
    let {
        uid
    } = ctx.query;
    // let sql = `SELECT * from vip WHERE uid = ${uid}`;
    if (uid) {
        try {
            // let info = (await Mysql(sql))[0];
            let sql1 = `SELECT * FROM vip WHERE uid = ${uid}`;
            let res1 = await Mysql(sql1);
            let sql2 = `SELECT * FROM intergal WHERE uid = ${uid}`;
            let res2 = await Mysql(sql2);
            let vipInfo = res1.length ? res1[0] : {
                endTime: 0
            };
            let info;
            if (vipInfo.endTime < Date.now()) {
                info = res2[0];
            } else {
                info = Object.assign({}, res1[0], res2[0]);
            }
            let infoStr = JSON.stringify(info);
            infoStr = Buffer.from(infoStr).toString('base64');
            ctx.state.data = {
                code: '001',
                data: encrypt(infoStr, 'yusupturak')
            }
        } catch (error) {
            ctx.state.data = {
                code: '002',
                msg: 'تەكشۈرۈش مەغلۇپ بولدى'
            }
        }
    } else {
        ctx.state.data = {
            code: '002',
            msg: 'تەكشۈرۈش مەغلۇپ بولدى'
        }
    }
}